// 2010-02-25 - M. Caputo

#ifndef GL_WIDGET_H
#define GL_WIDGET_H

#include <QtCore>
#include <QtOpenGL>

#include "IScene.h"
#include "IRenderMode.h"

class GlWidget : public QGLWidget
{

Q_OBJECT

public:
	GlWidget(QWidget *parent = 0);
	~GlWidget();
	
	void setScene(IScene *scene);
	
	void setBackgroundColor(const QColor & color);
	QColor backgroundColor();
	
	void setObjectColor(const QColor & color);
	QColor objectColor();
	
	void setXzPlane(bool status);
	void setXyPlane(bool status);
	void setYzPlane(bool status);
	
	bool xzPlane();
	bool xyPlane();
	bool yzPlane();
	
	void setAxes(bool status);
	bool axes();
	
	QStringList listRenderModes();
	void setRenderMode(int m);
	int renderMode();
	QString renderModeName();
	
	void resetView();
	
protected:
	void initializeGL();
	void resizeGL(int w, int h);
	void paintGL();
	void mousePressEvent(QMouseEvent *event);
	void mouseMoveEvent(QMouseEvent *event);
	void wheelEvent(QWheelEvent *event);
	void keyPressEvent(QKeyEvent *event);
	void keyReleaseEvent(QKeyEvent *event);

private:
	QVector<IRenderMode*> renderModes;
	int activeMode;
	IScene *scene;
	QPoint lastPos;
	QColor bgColor;
	QColor color;
	bool showAxes;
	bool showPlanes[3]; // xz, xy, zy
	float scale;
	float xTrans;
	float yTrans;
	float zTrans;
	int xRot;
	int yRot;
	int zRot;
	bool ctrlDown;
	bool altDown;

	void drawAxes();
	void drawXzPlane(int lines, float stepSize, const QColor & c);
	void drawXyPlane(int lines, float stepSize, const QColor & c);
	void drawYzPlane(int lines, float stepSize, const QColor & c);

	// do not allow copy constructor and = operator
	GlWidget(const GlWidget & other);
	GlWidget & operator=(const GlWidget& other);

};

#endif
